package animator.phantom.controller;

/*
    Copyright Janne Liljeblad

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

//--- Class for creating encode commands for Mencoder program
//--- and capturing whitch of its features are used and how.
public class FFMpegProg extends EncoderProgram
{
	private static final String VCOD = "-ovc";
	private static final String ACOD = "-oac";

	public FFMpegProg()
	{
		super( "ffmpeg", CodecController.FFMPEG );
		init();
	}

	public void init()
	{
		//--- Video codecs
		VideoCodec noopt = new VideoCodec( VideoCodec.NO_OPTIONS );
		VideoCodec mpg1 = new VideoCodec( VideoCodec.MPEG1VIDEO );
		VideoCodec mpg2 = new VideoCodec( VideoCodec.MPEG2VIDEO );
		VideoCodec theora = new VideoCodec( VideoCodec.THEORA );

		//--------------------------------------- Container formats
		//--- mov
		VideoFormat mov = new VideoFormat( VideoFormat.MOV );
		mov.addVCodec( noopt );

		//--- mpeg (1,2)
		VideoFormat mpg = new VideoFormat( VideoFormat.MPG );
		mpg.addVCodec( mpg1 );
		mpg.addVCodec( mpg2 );

		//--- ogg
		VideoFormat ogg = new VideoFormat( VideoFormat.OGG );
		ogg.addVCodec( theora );

		//addFormat( mov );
		//addFormat( mpg );
		addFormat( ogg );

		//-------------------------------------------- Decoding
		addDecodeFrameFormat( EncoderProgram.PNG );
		addDecodeFrameFormat( EncoderProgram.JPEG );
	}

	public String getCommand()
	{
		String command = 	COMMAND
					//--- set fps

					//--- set bitrate 
					+ " -b " + Integer.toString( VideoCodec.bitrate() * 1000 )
					//--- input file
					+ " -i frame%03d." + writeFrameType()	
					+ " -r " + ( new Integer( fps() )).toString() 
					//--- output file
					+ " " + movieName() + "." + fileExtension();


		return command;
	}
	
	public String getDecodeCommand()
	{
		//EXAMPLE: ffmpeg -i f-secure_firewall.mov -sameq %03d.jpg
		String command = 	COMMAND 
					+ " -i " + getDecodeMovie() 
					+ " -sameq %04d."
					+ getDecodeFrameFormat();

		return command;
	}

}//end class